package com.job.ZhangMeng.Homework0715;

public class StringDemo01 {

    public static void main(String[] args) {
        String s1="KGB";    //用字面值初始化字符串,视为常量,占用方法区内存字符串常量池
        String s2="KGB";
        System.out.println(s1==s2); //true

        String s3=new String("NKVD");   //用构造方法初始化字符串,会在堆内存申请空间
        String s4=new String("NKVD");
        System.out.println(s3==s4); //false
        s3=new String("ABC");
        s4=new String("ABC");
        System.out.println(s3==s1); //false
        System.out.println(s4==s1); //false
        // ==比较地址,重写的equals()方法比较内容

        //方法区字符串常量池的特点："ABC"+"D"->"ABCD"的过程是,
        //先申请空间存新字符串"D",再申请空间存结果"ABCD",三者均会存在
    }

}
